﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;
using System.Text.Json.Serialization;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentSpotRecordVMs
{
    public partial class EquipmentSpotRecordListVM : BasePagedListVM<EquipmentSpotRecord_View, EquipmentSpotRecordSearcher>
    {

        protected override IEnumerable<IGridColumn<EquipmentSpotRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<EquipmentSpotRecord_View>>{

                 this.MakeGridHeader(x => x.EquipmentSpotRecord_Equipment).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_SpotTableId).SetTitle(@Localizer["Page.点检表"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_LineId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_OpId).SetTitle(@Localizer["Page.工位"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_SpotType).SetTitle(@Localizer["Page.点检类型"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_Content).SetTitle(@Localizer["Page.点检内容"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_Status).SetTitle(@Localizer["Page.点检结果"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_UseOperator).SetTitle(@Localizer["Page.操作员"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotRecord_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),




                this.MakeGridHeaderAction(width: 200).SetHide(true)
            };
        }


        public override IOrderedQueryable<EquipmentSpotRecord_View> GetSearchQuery()
        {
            var query = DC.Set<EquipmentSpotRecord>()
                 .CheckEqual(Searcher.EquipmentId, x => x.EquipmentId)
                .CheckEqual(Searcher.LineId, x => x.LineId)
                .CheckContain(Searcher.LineCode, x => x.LineCode)
                .CheckEqual(Searcher.OpId, x => x.OpId)
                 .CheckEqual(Searcher.Status, x => x.Status)
                     .CheckEqual(Searcher.SpotType, x => x.SpotType)
                .CheckContain(Searcher.OpCode, x => x.OpCode)
                .CheckContain(Searcher.UseOperator, x => x.UseOperator)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x => x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x => x.UpdateBy)
                                .Select(x => new EquipmentSpotRecord_View
                                {
                                    EquipmentSpotRecord_Equipment = x.SpotTable.Equipment.EquipName,
                                    EquipmentSpotRecord_SpotTableId=x.SpotTable.FormNo,
                                    EquipmentSpotRecord_OpId=x.SpotTable.OpCode,
                                    EquipmentSpotRecord_SpotType=x.SpotType,
                                    EquipmentSpotRecord_Content=x.Content,
                                    EquipmentSpotRecord_Status=x.Status,
                                    EquipmentSpotRecord_UseOperator=x.UseOperator,
                                    EquipmentSpotRecord_CreateBy=x.CreateBy,
                                    EquipmentSpotRecord_UpdateBy=x.UpdateBy,
                                    EquipmentSpotRecord_CreateTime=x.CreateTime,
                                    EquipmentSpotRecord_UpdateTime=x.UpdateTime,
                                    ID = x.ID,
                                })
                .OrderBy(x => x.ID);
            return query;
        }


    }
    public class EquipmentSpotRecord_View : EquipmentSpotRecord
    {

        public string EquipmentSpotRecord_Equipment { get; set; }

        public string EquipmentSpotRecord_SpotTableId { get; set; }


        public string EquipmentSpotRecord_LineId { get; set; }


        public string EquipmentSpotRecord_OpId { get; set; }


        public SpotTypeEnum? EquipmentSpotRecord_SpotType { get; set; }


        public string EquipmentSpotRecord_Content { get; set; }


        public SpotStatusEnum? EquipmentSpotRecord_Status { get; set; }


        public string EquipmentSpotRecord_UseOperator { get; set; }



        public DateTime? EquipmentSpotRecord_CreateTime { get; set; }
        public DateTime? EquipmentSpotRecord_UpdateTime { get; set; }
        public string EquipmentSpotRecord_CreateBy { get; set; }
        public string EquipmentSpotRecord_UpdateBy { get; set; }
    }

}